function window(s) {
    const len = s.length
    const set = new Set()
    let left = 0, ans = 0
    for (let right = 0; right < len; right++) {
        let c= s[right]
        if(set.has(c)){  //保证左右窗口里都是不重复的
            set.delete(s[left++])
        }
        set.add(c)
        ans = Math.max(ans,right-left+1)
    }
    console.log('set:',set)  
    return ans
}

function mapFn(s){
    let len= s.length
    let map = new Map()     
    let max =0,start = 0
    for(let i =0;i<len;i++){
        let c = s[i]
        while(map[c]&&map[c]>start){       //字母第二次出现
            start++
        }
        map[c] = i          //记录字母唯一一次出现的下标
        max = Math.max(max,i-start)
    }   
    console.log(map)  
    return max
}
// function getLongStr(s){
//     let start = 0
//     let max = 0
//     let map = {}
//     for(let i =0;i<s.length;i++){
//         if(s[i] in map && map[s[i]]>=start){
//             start = map[s[i]]+1
//         }else {
//             max=Math.max(max,i-start+1)
//         }
//         map[s[i]] = i
//     }
//     return max
// }

// let s = "abcabcbb";
// console.log(getLongStr(s)); 

console.log(window('aabacdbe'))
console.log(mapFn('aabacdbe'))
